import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sainbainu/common/values/colors.dart';

class JoinBtn extends StatefulWidget {
  final VoidCallback onJoin;
  const JoinBtn({super.key, required this.onJoin});

  @override
  State<JoinBtn> createState() => _JoinBtnState();
}

class _JoinBtnState extends State<JoinBtn> {
  bool isJoined = false;

  @override
  Widget build(BuildContext context) {
    Widget btn;
    if (isJoined) {
      btn = OutlinedButton(
        onPressed: null,
        style: OutlinedButton.styleFrom(
          padding: const EdgeInsets.all(0),
          side: const BorderSide(color: AppColors.danger, width: 1),
          foregroundColor: Colors.white,
        ),
        child: Text(
          '已加入'.tr,
          style: const TextStyle(color: AppColors.danger, fontSize: 12),
        ),
      );
    } else {
      btn = ElevatedButton(
        onPressed: () {
          isJoined = true;
          widget.onJoin();
        },
        style: ElevatedButton.styleFrom(
          padding: const EdgeInsets.all(0),
          backgroundColor: AppColors.danger,
          foregroundColor: Colors.white,
          enableFeedback: true,
        ),
        child: Text(
          '加入'.tr,
          style: const TextStyle(color: Colors.white, fontSize: 12),
        ),
      );
    }
    return SizedBox(
      width: 62,
      height: 24,
      child: btn,
    );
  }
}
